package com.ruoyi.wb.service.impl;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.wb.domain.WbInform;
import com.ruoyi.wb.enmus.WbInformType;
import com.ruoyi.wb.mapper.WbInformMapper;
import com.ruoyi.wb.service.IWbInformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 消息Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-10-14
 */
@Service
public class WbInformServiceImpl implements IWbInformService
{
    @Autowired
    private WbInformMapper wbInformMapper;

    /**
     * 查询消息
     * 
     * @param id 消息主键
     * @return 消息
     */
    @Override
    public WbInform selectWbInformById(Long id)
    {
        return wbInformMapper.selectWbInformById(id);
    }

    /**
     * 查询消息列表
     * 
     * @param wbInform 消息
     * @return 消息
     */
    @Override
    public List<WbInform> selectWbInformList(WbInform wbInform)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if (!ObjectUtils.isEmpty(wbInform.getInformType())&&wbInform.getInformType().equals(WbInformType.ORDER_NOTICE.getCode())){
            wbInform.setClientId(loginUser.getUserId());
          //  wbInform.setClientName(loginUser.getUser().getNickName());
        }else if (!ObjectUtils.isEmpty(wbInform.getInformType())&&wbInform.getInformType().equals(WbInformType.EXAMINING_REPORT.getCode())){
              if (ObjectUtils.isEmpty(wbInform.getClientId())){
               return new ArrayList<WbInform>();
              }
        }else {
            return new ArrayList<WbInform>();
        }
        return wbInformMapper.selectWbInformList(wbInform);
    }

    /**
     * 新增消息
     * 
     * @param wbInform 消息
     * @return 结果
     */
    @Override
    public int insertWbInform(WbInform wbInform)
    {
        wbInform.setCreateTime(DateUtils.getNowDate());
        return wbInformMapper.insertWbInform(wbInform);
    }

    /**
     * 修改消息
     * 
     * @param wbInform 消息
     * @return 结果
     */
    @Override
    public int updateWbInform(WbInform wbInform)
    {
        wbInform.setUpdateTime(DateUtils.getNowDate());
        return wbInformMapper.updateWbInform(wbInform);
    }

    /**
     * 批量删除消息
     * 
     * @param ids 需要删除的消息主键
     * @return 结果
     */
    @Override
    public int deleteWbInformByIds(Long[] ids)
    {
        return wbInformMapper.deleteWbInformByIds(ids);
    }

    /**
     * 删除消息信息
     * 
     * @param id 消息主键
     * @return 结果
     */
    @Override
    public int deleteWbInformById(Long id)
    {
        return wbInformMapper.deleteWbInformById(id);
    }

    @Override
    public int getCount() {
        return wbInformMapper.getCount(SecurityUtils.getLoginUser().getUserId(), WbInformType.UNREAD.getCode());
    }
}
